<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>animationqueue_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_fx_animationqueue_test.js.html">animationqueue_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.fx.AnimationQueueTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.fx.AnimationQueueTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.events&#39;);
<a name="line19"></a>goog.require(&#39;goog.fx.Animation&#39;);
<a name="line20"></a>goog.require(&#39;goog.fx.AnimationParallelQueue&#39;);
<a name="line21"></a>goog.require(&#39;goog.fx.AnimationSerialQueue&#39;);
<a name="line22"></a>goog.require(&#39;goog.fx.Transition&#39;);
<a name="line23"></a>goog.require(&#39;goog.fx.anim&#39;);
<a name="line24"></a>goog.require(&#39;goog.testing.MockClock&#39;);
<a name="line25"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line26"></a>
<a name="line27"></a>var clock;
<a name="line28"></a>
<a name="line29"></a>function setUpPage() {
<a name="line30"></a>  clock = new goog.testing.MockClock(true);
<a name="line31"></a>  goog.fx.anim.setAnimationWindow(null);
<a name="line32"></a>}
<a name="line33"></a>
<a name="line34"></a>function tearDownPage() {
<a name="line35"></a>  clock.dispose();
<a name="line36"></a>}
<a name="line37"></a>
<a name="line38"></a>function testParallelEvents() {
<a name="line39"></a>  var anim = new goog.fx.AnimationParallelQueue();
<a name="line40"></a>  anim.add(new goog.fx.Animation([0], [100], 200));
<a name="line41"></a>  anim.add(new goog.fx.Animation([0], [100], 400));
<a name="line42"></a>  anim.add(new goog.fx.Animation([0], [100], 600));
<a name="line43"></a>
<a name="line44"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line45"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line46"></a>  assertTrue(anim.queue[2].isStopped());
<a name="line47"></a>  assertTrue(anim.isStopped());
<a name="line48"></a>
<a name="line49"></a>  var playEvents = 0, beginEvents = 0, resumeEvents = 0, pauseEvents = 0;
<a name="line50"></a>  var endEvents = 0, stopEvents = 0, finishEvents = 0;
<a name="line51"></a>
<a name="line52"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.PLAY, function() {
<a name="line53"></a>    ++playEvents; });
<a name="line54"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.BEGIN, function() {
<a name="line55"></a>    ++beginEvents; });
<a name="line56"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.RESUME, function() {
<a name="line57"></a>    ++resumeEvents; });
<a name="line58"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.PAUSE, function() {
<a name="line59"></a>    ++pauseEvents; });
<a name="line60"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.END, function() {
<a name="line61"></a>    ++endEvents; });
<a name="line62"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.STOP, function() {
<a name="line63"></a>    ++stopEvents; });
<a name="line64"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.FINISH, function() {
<a name="line65"></a>    ++finishEvents; });
<a name="line66"></a>
<a name="line67"></a>  // PLAY, BEGIN
<a name="line68"></a>  anim.play();
<a name="line69"></a>  // No queue events.
<a name="line70"></a>  clock.tick(100);
<a name="line71"></a>  // PAUSE
<a name="line72"></a>  anim.pause();
<a name="line73"></a>  // No queue events
<a name="line74"></a>  clock.tick(200);
<a name="line75"></a>  // PLAY, RESUME
<a name="line76"></a>  anim.play();
<a name="line77"></a>  // No queue events.
<a name="line78"></a>  clock.tick(400);
<a name="line79"></a>  // END, STOP
<a name="line80"></a>  anim.stop();
<a name="line81"></a>  // PLAY, BEGIN
<a name="line82"></a>  anim.play();
<a name="line83"></a>  // No queue events.
<a name="line84"></a>  clock.tick(400);
<a name="line85"></a>  // END, FINISH
<a name="line86"></a>  clock.tick(200);
<a name="line87"></a>
<a name="line88"></a>  // Make sure the event counts are right.
<a name="line89"></a>  assertEquals(3, playEvents);
<a name="line90"></a>  assertEquals(2, beginEvents);
<a name="line91"></a>  assertEquals(1, resumeEvents);
<a name="line92"></a>  assertEquals(1, pauseEvents);
<a name="line93"></a>  assertEquals(2, endEvents);
<a name="line94"></a>  assertEquals(1, stopEvents);
<a name="line95"></a>  assertEquals(1, finishEvents);
<a name="line96"></a>}
<a name="line97"></a>
<a name="line98"></a>function testSerialEvents() {
<a name="line99"></a>  var anim = new goog.fx.AnimationSerialQueue();
<a name="line100"></a>  anim.add(new goog.fx.Animation([0], [100], 100));
<a name="line101"></a>  anim.add(new goog.fx.Animation([0], [100], 200));
<a name="line102"></a>  anim.add(new goog.fx.Animation([0], [100], 300));
<a name="line103"></a>
<a name="line104"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line105"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line106"></a>  assertTrue(anim.queue[2].isStopped());
<a name="line107"></a>  assertTrue(anim.isStopped());
<a name="line108"></a>
<a name="line109"></a>  var playEvents = 0, beginEvents = 0, resumeEvents = 0, pauseEvents = 0;
<a name="line110"></a>  var endEvents = 0, stopEvents = 0, finishEvents = 0;
<a name="line111"></a>
<a name="line112"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.PLAY, function() {
<a name="line113"></a>    ++playEvents; });
<a name="line114"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.BEGIN, function() {
<a name="line115"></a>    ++beginEvents; });
<a name="line116"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.RESUME, function() {
<a name="line117"></a>    ++resumeEvents; });
<a name="line118"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.PAUSE, function() {
<a name="line119"></a>    ++pauseEvents; });
<a name="line120"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.END, function() {
<a name="line121"></a>    ++endEvents; });
<a name="line122"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.STOP, function() {
<a name="line123"></a>    ++stopEvents; });
<a name="line124"></a>  goog.events.listen(anim, goog.fx.Transition.EventType.FINISH, function() {
<a name="line125"></a>    ++finishEvents; });
<a name="line126"></a>
<a name="line127"></a>  // PLAY, BEGIN
<a name="line128"></a>  anim.play();
<a name="line129"></a>  // No queue events.
<a name="line130"></a>  clock.tick(100);
<a name="line131"></a>  // PAUSE
<a name="line132"></a>  anim.pause();
<a name="line133"></a>  // No queue events
<a name="line134"></a>  clock.tick(200);
<a name="line135"></a>  // PLAY, RESUME
<a name="line136"></a>  anim.play();
<a name="line137"></a>  // No queue events.
<a name="line138"></a>  clock.tick(400);
<a name="line139"></a>  // END, STOP
<a name="line140"></a>  anim.stop();
<a name="line141"></a>  // PLAY, BEGIN
<a name="line142"></a>  anim.play(true);
<a name="line143"></a>  // No queue events.
<a name="line144"></a>  clock.tick(400);
<a name="line145"></a>  // END, FINISH
<a name="line146"></a>  clock.tick(200);
<a name="line147"></a>
<a name="line148"></a>  // Make sure the event counts are right.
<a name="line149"></a>  assertEquals(3, playEvents);
<a name="line150"></a>  assertEquals(2, beginEvents);
<a name="line151"></a>  assertEquals(1, resumeEvents);
<a name="line152"></a>  assertEquals(1, pauseEvents);
<a name="line153"></a>  assertEquals(2, endEvents);
<a name="line154"></a>  assertEquals(1, stopEvents);
<a name="line155"></a>  assertEquals(1, finishEvents);
<a name="line156"></a>}
<a name="line157"></a>
<a name="line158"></a>function testParallelPause() {
<a name="line159"></a>  var anim = new goog.fx.AnimationParallelQueue();
<a name="line160"></a>  anim.add(new goog.fx.Animation([0], [100], 100));
<a name="line161"></a>  anim.add(new goog.fx.Animation([0], [100], 200));
<a name="line162"></a>  anim.add(new goog.fx.Animation([0], [100], 300));
<a name="line163"></a>
<a name="line164"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line165"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line166"></a>  assertTrue(anim.queue[2].isStopped());
<a name="line167"></a>  assertTrue(anim.isStopped());
<a name="line168"></a>
<a name="line169"></a>  anim.play();
<a name="line170"></a>
<a name="line171"></a>  assertTrue(anim.queue[0].isPlaying());
<a name="line172"></a>  assertTrue(anim.queue[1].isPlaying());
<a name="line173"></a>  assertTrue(anim.queue[2].isPlaying());
<a name="line174"></a>  assertTrue(anim.isPlaying());
<a name="line175"></a>
<a name="line176"></a>  clock.tick(100);
<a name="line177"></a>
<a name="line178"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line179"></a>  assertTrue(anim.queue[1].isPlaying());
<a name="line180"></a>  assertTrue(anim.queue[2].isPlaying());
<a name="line181"></a>  assertTrue(anim.isPlaying());
<a name="line182"></a>
<a name="line183"></a>  anim.pause();
<a name="line184"></a>
<a name="line185"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line186"></a>  assertTrue(anim.queue[1].isPaused());
<a name="line187"></a>  assertTrue(anim.queue[2].isPaused());
<a name="line188"></a>  assertTrue(anim.isPaused());
<a name="line189"></a>
<a name="line190"></a>  clock.tick(200);
<a name="line191"></a>
<a name="line192"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line193"></a>  assertTrue(anim.queue[1].isPaused());
<a name="line194"></a>  assertTrue(anim.queue[2].isPaused());
<a name="line195"></a>  assertTrue(anim.isPaused());
<a name="line196"></a>
<a name="line197"></a>  anim.play();
<a name="line198"></a>
<a name="line199"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line200"></a>  assertTrue(anim.queue[1].isPlaying());
<a name="line201"></a>  assertTrue(anim.queue[2].isPlaying());
<a name="line202"></a>  assertTrue(anim.isPlaying());
<a name="line203"></a>
<a name="line204"></a>  clock.tick(100);
<a name="line205"></a>
<a name="line206"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line207"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line208"></a>  assertTrue(anim.queue[2].isPlaying());
<a name="line209"></a>  assertTrue(anim.isPlaying());
<a name="line210"></a>
<a name="line211"></a>  anim.pause();
<a name="line212"></a>
<a name="line213"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line214"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line215"></a>  assertTrue(anim.queue[2].isPaused());
<a name="line216"></a>  assertTrue(anim.isPaused());
<a name="line217"></a>
<a name="line218"></a>  clock.tick(200);
<a name="line219"></a>
<a name="line220"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line221"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line222"></a>  assertTrue(anim.queue[2].isPaused());
<a name="line223"></a>  assertTrue(anim.isPaused());
<a name="line224"></a>
<a name="line225"></a>  anim.play();
<a name="line226"></a>
<a name="line227"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line228"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line229"></a>  assertTrue(anim.queue[2].isPlaying());
<a name="line230"></a>  assertTrue(anim.isPlaying());
<a name="line231"></a>
<a name="line232"></a>  clock.tick(100);
<a name="line233"></a>
<a name="line234"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line235"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line236"></a>  assertTrue(anim.queue[2].isStopped());
<a name="line237"></a>  assertTrue(anim.isStopped());
<a name="line238"></a>}
<a name="line239"></a>
<a name="line240"></a>function testSerialPause() {
<a name="line241"></a>  var anim = new goog.fx.AnimationSerialQueue();
<a name="line242"></a>  anim.add(new goog.fx.Animation([0], [100], 100));
<a name="line243"></a>  anim.add(new goog.fx.Animation([0], [100], 200));
<a name="line244"></a>  anim.add(new goog.fx.Animation([0], [100], 300));
<a name="line245"></a>
<a name="line246"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line247"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line248"></a>  assertTrue(anim.queue[2].isStopped());
<a name="line249"></a>  assertTrue(anim.isStopped());
<a name="line250"></a>
<a name="line251"></a>  anim.play();
<a name="line252"></a>
<a name="line253"></a>  assertTrue(anim.queue[0].isPlaying());
<a name="line254"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line255"></a>  assertTrue(anim.queue[2].isStopped());
<a name="line256"></a>  assertTrue(anim.isPlaying());
<a name="line257"></a>
<a name="line258"></a>  clock.tick(100);
<a name="line259"></a>
<a name="line260"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line261"></a>  assertTrue(anim.queue[1].isPlaying());
<a name="line262"></a>  assertTrue(anim.queue[2].isStopped());
<a name="line263"></a>  assertTrue(anim.isPlaying());
<a name="line264"></a>
<a name="line265"></a>  anim.pause();
<a name="line266"></a>
<a name="line267"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line268"></a>  assertTrue(anim.queue[1].isPaused());
<a name="line269"></a>  assertTrue(anim.queue[2].isStopped());
<a name="line270"></a>  assertTrue(anim.isPaused());
<a name="line271"></a>
<a name="line272"></a>  clock.tick(400);
<a name="line273"></a>
<a name="line274"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line275"></a>  assertTrue(anim.queue[1].isPaused());
<a name="line276"></a>  assertTrue(anim.queue[2].isStopped());
<a name="line277"></a>  assertTrue(anim.isPaused());
<a name="line278"></a>
<a name="line279"></a>  anim.play();
<a name="line280"></a>
<a name="line281"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line282"></a>  assertTrue(anim.queue[1].isPlaying());
<a name="line283"></a>  assertTrue(anim.queue[2].isStopped());
<a name="line284"></a>  assertTrue(anim.isPlaying());
<a name="line285"></a>
<a name="line286"></a>  clock.tick(200);
<a name="line287"></a>
<a name="line288"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line289"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line290"></a>  assertTrue(anim.queue[2].isPlaying());
<a name="line291"></a>  assertTrue(anim.isPlaying());
<a name="line292"></a>
<a name="line293"></a>  anim.pause();
<a name="line294"></a>
<a name="line295"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line296"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line297"></a>  assertTrue(anim.queue[2].isPaused());
<a name="line298"></a>  assertTrue(anim.isPaused());
<a name="line299"></a>
<a name="line300"></a>  clock.tick(300);
<a name="line301"></a>
<a name="line302"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line303"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line304"></a>  assertTrue(anim.queue[2].isPaused());
<a name="line305"></a>  assertTrue(anim.isPaused());
<a name="line306"></a>
<a name="line307"></a>  anim.play();
<a name="line308"></a>
<a name="line309"></a>  clock.tick(300);
<a name="line310"></a>
<a name="line311"></a>  assertTrue(anim.queue[0].isStopped());
<a name="line312"></a>  assertTrue(anim.queue[1].isStopped());
<a name="line313"></a>  assertTrue(anim.queue[2].isStopped());
<a name="line314"></a>  assertTrue(anim.isStopped());
<a name="line315"></a>}
</pre>


</body>
</html>
